package com.zhifa.hdtyg_cdgl.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zhifa.hdtyg_cdgl.entity.SiteMaintenance;
import com.zhifa.hdtyg_cdgl.service.SiteInformationService;
import com.zhifa.hdtyg_cdgl.service.SiteMaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/siteMaintenance")
public class SiteMaintenanceController {

    @Autowired
    SiteMaintenanceService siteMaintenanceService;

    @Autowired
    SiteInformationService siteInformationService;

    @RequestMapping("/findAllSiteMaintenance")
    public JSONObject findAllSiteMaintenance(SiteMaintenance siteMaintenance, int page , int rows){
        return siteMaintenanceService.findAllSiteMaintenance(siteMaintenance, page, rows);
    }


    @RequestMapping("/addSiteMaintenance")
    public Map<String,Object>addSiteMaintenance(SiteMaintenance siteMaintenance,HttpSession httpSession){
        siteMaintenance.setStatus("正在维修");
        Integer adminId=(Integer) httpSession.getAttribute("user_id");
        int info = siteMaintenanceService.addSiteMaintenance(siteMaintenance,adminId);
        Map<String,Object> map=new HashMap<>();
        if (info>0){
            map.put("success",true);
        }else {
            map.put("success",false);
        }
        return map;
    }

    @RequestMapping("/findStatus")
    public JSONArray findStatus(){
        return siteMaintenanceService.findStatus();
    }

    @RequestMapping("/resatarWeixiuStatus")
    public Map<String,Object> resatarWeixiuStatus(SiteMaintenance siteMaintenance , HttpSession httpSession){
        siteMaintenance.setStatus("可租借");
        Integer adminId=(Integer) httpSession.getAttribute("user_id");
        int i = siteMaintenanceService.resatarWeixiuStatus(siteMaintenance, adminId);
        Map<String,Object> map=new HashMap<>();
        if (i>0){
            map.put("success",true);
        }else {
            map.put("success",false);
        }
        return map;
    }

}
